package com.kuang.springcloud.service.impl;

import com.kuang.springcloud.dao.DeptDao;
import com.kuang.springcloud.pojo.Dept;
import com.kuang.springcloud.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class DeptServiceImpl implements DeptService {

    @Autowired
    private DeptDao deptDao;

    @Override
    public boolean addDept(Dept dept) {
        Dept dept1 = deptDao.finByDname(dept.getDname());
        System.out.println("数据是否存在"+dept1);
        if (dept1 != null) {
            return false;
        }

        boolean b = deptDao.addDept(dept);
        if (b) {
            System.out.println(dept.getDname() + "添加成功");
        } else {
            System.out.println(dept.getDname() + "添加失败");
        }

        return b;
    }

    @Override
    public Dept queryById(Integer id) {
        Dept dept = deptDao.queryById(id);
        System.out.println("数据为::" + dept);
        return dept;
    }

    @Override
    public List<Dept> queryAll() {
        List<Dept> depts = deptDao.queryAll();
        System.out.println("数据为::" + depts);
        return depts;
    }
}
